<%@ page contentType="text/html;charset=UTF-8" %> 
<%@ include file="/include.inc.jsp"%>
<style type="text/css">
<!--
.order{
	width: 120px;
}
-->
</style>

<div class="pageContent">
<form method="post" id="sysUserDeskForm" action="${ctx}/sysUserDesk/save2" class="pageForm required-validate" onsubmit="return validateCallback(this,navTabAjaxDone);">
    <input type="hidden" name="id" value="-1"/>
    <div class="panelBar">
        <ul class="toolBar">
            <shiro:hasPermission name="sysUserDesk:edit">
			<li><a class="save" href="#" onclick="hrefSaveUserDesk_OnClick('sysUserDeskForm')"><span>保存</span></a></li>
            </shiro:hasPermission>
        </ul>
    </div>
    <div class="pageFormContent nowrap" layoutH="56">
<table class="table" width="100%" layoutH="138" id="table1">
		<thead>
			<tr>
				<th width="40" align="center">
					<input type="checkbox" name="allUserDesk" onclick="UserDesk_checkAll(this,'checkboxUserDeskId')" title="全选"/>
				</th>
				<th>项目名称</th>
				<th>显示顺序</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${usingDeskList}" var="usingDesk" varStatus="c">
				<tr target="noCheck" rel="${usingDesk.sysDeskId}">
					<td align="center">
                     	<input type="checkbox"  name="checkboxUserDeskId" value="${usingDesk.sysDeskId}" checked="checked" onClick="sele(this)"/>
                		<span></span><%-- 此span标签有动态生成的提交数据,请不要删除 --%>
                	</td>
					<td>${usingDesk.titleName}</td>
					<td><input class="order" type="text" value="${usingDesk.showOrder}" onkeyup="isNumber(this)" onblur="isNull(this)"/></td>
				</tr>
			</c:forEach>
		
			<c:forEach items="${unusedDeskList}" var="unusedDesk">
				<tr target="noCheck" rel="${unusedDesk.id}">
					<td align="center">
                     	<input type="checkbox" name="checkboxUserDeskId" value="${unusedDesk.id}" onClick="sele(this)"/>
                     	<span></span><%-- 此span标签有动态生成的提交数据,请不要删除 --%>
                	</td>
					<td>${unusedDesk.titleName}</td>
					<td></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
    </div>
</form>
<script type="text/javascript">
function hrefSaveUserDesk_OnClick(formName){
	$("input[name='checkboxUserDeskId']:checkbox:checked").each(function(i) {
		$(this).next().empty();// 清空提交内容再添加，反正连续点击提交按钮产生多个提交数据
		var val= $(this).val();// 桌面配置项ID
		var order = $(this).parent().parent().next().next().find("input").val();
		$(this).next().append("<input type='hidden' name='sysUserDeskList["+i+"].sysDeskId' value='"+val+"' /> <input type='hidden' name='sysUserDeskList["+i+"].showOrder' value='"+order+"' />");
	});
	$("#"+formName).submit();
}
function sele(e){
	$(e).next().empty();// 防止第一次提交不成功后，修改再提交引起数据多提交
	if($(e).prop("checked") == "checked" || $(e).prop("checked") == true) {
		$(e).parent().parent().next().next().html("");
		$(e).parent().parent().next().next().append("<input class='order' type='text' value='0' onkeyup='isNumber(this)' onblur='isNull(this)' />");
	}else {
		$(e).parent().parent().next().next().html("");
		$("input[name=allUserDesk]").prop("checked",false);
	}
}
function UserDesk_checkAll(evt,checkName){
	if($(evt).prop("checked") == "checked" || $(evt).prop("checked") == true) { // 选择所有
		$("input[name='"+checkName+"']").each(function() {
			if($(this).prop("checked") != "checked" && $(this).prop("checked") != true) {
				$(this).prop("checked", "checked");
				sele(this);
			}
		});
	} else {
		$("input[name='"+checkName+"']").prop("checked",false);
		$("input[name='"+checkName+"']").each(function(i) {
			sele(this);
		});
	}
}
function isNumber(e){
	reg = /^[1-9]\d*$/;   
	if(!reg.test($(e).val())) {
		$(e).val("");
	}
}
function isNull(e){
	var val = $(e).val();
	if(val == "") {
		$(e).val(0);
	}
}
</script>
</div>